package com.wuming.house.service.impl;

import com.wuming.house.core.BusinessException;
import com.wuming.house.dao.SecondhousepriceMapper;
import com.wuming.house.model.Secondhouseprice;
import com.wuming.house.service.SecondhousepriceService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("secondhousepriceService")
public class SecondhousepriceServiceImpl extends BaseServiceImpl implements SecondhousepriceService {

    @Autowired
    private SecondhousepriceMapper secondhousepriceMapper;

    @Override
    public void saveSecondhouseprice(Secondhouseprice houseprice) throws BusinessException {
        secondhousepriceMapper.insert(houseprice);
    }

    @Override
    public void modifySecondhouseprice(Secondhouseprice houseprice) throws BusinessException {
        secondhousepriceMapper.updateByPrimaryKey(houseprice);
    }

    @Override
    public Secondhouseprice getSecondhousepriceById(Long id) throws BusinessException {
        return secondhousepriceMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Secondhouseprice> getSecondhousepriceByParams(Long houseId, String houseName, Integer year, Integer month) throws BusinessException {
        Map<String, Object> params = new HashMap<>();
        if (null != houseId) {
            params.put("houseId", houseId);
        }
        if (StringUtils.isNotBlank(houseName)) {
            params.put("houseName", houseName);
        }
        if (null != year) {
            params.put("year", year);
        }
        if (null != month) {
            params.put("month", month);
        }
        return secondhousepriceMapper.selectByParams(params);
    }
}
